package com.zhfj.controller.portal;

import com.zhfj.entity.UserEntity;
import com.zhfj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;

/**
 * Created on 2017/12/1.
 *
 * @author Jie
 */
@Controller
public class TestController {

    @Autowired
    private UserService userService;

    @RequestMapping("/user/{id}")
    @ResponseBody
    public UserEntity findById(@PathVariable("id")Integer id){
        return userService.findById(id);
    }

    @RequestMapping(value = "/user/upload" ,method = RequestMethod.POST)
    @ResponseBody
    public String uploadImages(MultipartFile file, HttpServletRequest request){
        String fileName = file.getOriginalFilename();
        String contentType = file.getContentType();
        System.out.println("name : " + fileName + " , contentType : " +contentType);
        File newFile = new File(fileName);
        try {
            file.transferTo(newFile);
            System.out.println(newFile.getAbsolutePath());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "success";
    }


    @RequestMapping("/article/{id}")
    public String showarticle(@PathVariable("id")int id){

        return "blog";
    }
}
